//
//  ControlButton.m
//  Mahjong
//
//  Created by 饶首建 on 17/5/15.
//  Copyright © 2017年 com.ikamobile.com. All rights reserved.
//

#import "ControlButton.h"


@implementation ControlButton

- (instancetype)initWithTitle:(NSString *)title fontSize:(CGFloat)size{
    self = [super init];
    if (self) {
        [self setTitle:title forState:UIControlStateNormal];
        [self setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
        [self setTitleColor:[UIColor lightGrayColor] forState:UIControlStateHighlighted];
        
        self.titleLabel.font = DefaultSystemFont(size);
        self.layer.borderWidth = 0.5f;
        self.layer.borderColor = [UIColor grayColor].CGColor;
        self.layer.cornerRadius = 4;
        self.layer.masksToBounds = YES;
        
        [self sizeToFit];
    }
    return self;
}

- (instancetype)initWithTitle:(NSString *)title fontSize:(CGFloat)size bgColor:(UIColor*)bgColor{
    self = [super init];
    if (self) {
        [self setTitle:title forState:UIControlStateNormal];
        self.titleLabel.font = DefaultSystemFont(size);
        [self setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
        [self setTitleColor:[UIColor lightGrayColor] forState:UIControlStateHighlighted];
        self.backgroundColor = bgColor;
        self.layer.cornerRadius = 4;
        self.layer.masksToBounds = YES;
        [self sizeToFit];
    }
    return self;
}

- (instancetype)initWithTitle:(NSString *)title fontSize:(CGFloat)size cornerRadius:(CGFloat)cornerRadius{
    self = [super init];
    if (self) {
        [self setTitle:title forState:UIControlStateNormal];
        [self setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
        [self setTitleColor:[UIColor lightGrayColor] forState:UIControlStateHighlighted];
        self.titleLabel.font = DefaultSystemFont(size);
        self.titleLabel.adjustsFontSizeToFitWidth = YES;
        self.layer.borderWidth = 0.5f;
        self.layer.borderColor = [UIColor grayColor].CGColor;
        self.layer.cornerRadius = cornerRadius;
        self.layer.masksToBounds = YES;
        
        [self sizeToFit];
    }
    return self;
}

- (instancetype)initWithTitle1:(NSString *)title fontSize:(CGFloat)size cornerRadius:(CGFloat)cornerRadius{
    self = [super init];
    if (self) {
        [self setTitle:title forState:UIControlStateNormal];
        [self setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
        [self setTitleColor:[UIColor lightGrayColor] forState:UIControlStateHighlighted];
        
//        self.backgroundColor = [UIColor lightGrayColor];
        
        self.titleLabel.font = DefaultSystemFont(size);
        
        [self sizeToFit];
    }
    return self;
}



- (void)addTapBlock:(ButtonBlock)block{
    _block = block;
    [self addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
}

- (void)buttonAction:(UIButton *)button{
    _block(button);
}


@end
